		var editIndex = undefined;

		function submitFormAdvance() {//带对象form提交
			var jsonString = JSON.stringify(serializeToJSON('#ff'));
			//alert(jsonString);
			ajaxSubmitForm(jsonString);
		}

		function submitFormAdvanceOption(formname, updateAction, url) {//带对象form提交，带参数
			var jsonString = JSON.stringify(serializeToJSON(formname));
			//console.log(jsonString);
			ajaxSubmitFormOption(jsonString, updateAction, url);
		}
		
		function serializeToJSON(formname) {
			//var serializeObj=serializeForm($(formname));  
			//console.info(paramString2obj($(formname)));
			//console.info(serializeForm($(formname)));
			//console.log($.formHelper.getObject($(formname).serialize()));
			var serializeObj=$.formHelper.getObject($(formname).serialize());
		    return serializeObj;   
		}
		
		function submitForm() {//普通提交
			var jsonString = JSON.stringify(serializeToJSONSimply('#ff'));
			//console.log(jsonString);
			ajaxSubmitForm(jsonString);
		}
		
		function serializeToJSONSimply(formname) {
			var serializeObj=serializeForm($(formname));  
			//console.info(serializeObj);
		    return serializeObj;   
		}
		
		function submitFormOption(formname, updateAction, url) {//普通提交，带参数
			var jsonString = JSON.stringify(serializeToJSONSimply(formname));
			//console.log(jsonString);
			ajaxSubmitFormOption(jsonString, updateAction, url);
		}

		function serializeForm(form) { /* 将form表单内的元素序列化为对象，扩展Jquery的一个方法 */
			var o = {};
			$.each(form.serializeArray(), function(index) {
				if (o[this['name']]) {
					o[this['name']] = o[this['name']] + "," + this['value'];
				} else {
					o[this['name']] = this['value'];
				}
			});
			return o;
		}
		
		jQuery.formHelper = {
			    getObject: function (urlserialize) {
			        if (urlserialize) {
			            urlserialize = decodeURIComponent(urlserialize.replace(/\+/g," "));
			            var kvs = $.map((urlserialize).split('&'), function (e, i) {
			                var kv = (e + '').split('=');
			                return { key: kv[0], value: kv[1] };
			            });
			            var params = {};
			            for (var key in kvs) {
			                var _key = kvs[key].key;
			                var value = null;
			                if (typeof (params[_key]) == 'undefined') {
			                    if ($.grep(kvs, function (e, i) { return e.key == _key; }).length > 1) {
			                        value = [];
			                        value.push(kvs[key].value);
			                        params[_key] = value;
			                    } else {
			                        value = kvs[key].value;
			                        params[_key] = value;
			                    }
			                } else if (typeof (params[_key]) == 'object') {
			                    value = params[_key] ? params[_key] : [];
			                    value.push(kvs[key].value);
			                    params[_key] = value;
			                } else {
			                    value = kvs[key].value;
			                    params[_key] = value;
			                }
			            }
			            var resultParams = {};
			            var objectParams = [];
			            var indexs = {};
			            for (var key in params) {
			                var lstKey = key.substr(key.length - 6, 6);
			                var subKey = key.substr(0, key.length - 6);
			                var isIndex = (lstKey == '.index' && (urlserialize.indexOf(subKey + '[') == 0 || urlserialize.indexOf('&' + subKey + '[') > 0));
			                var indexArr = key.match(/\[([^\]]+)\]/ig);
			                if (indexArr) {
			                    var __key = key;
			                    for (var i = 0; i < indexArr.length; i++) {
			                        var _index = (indexArr[i] + '');//.replace(/[\[\]]/g, '');
			                        var indexof = __key.indexOf(indexArr[i]);
			                        if (typeof (indexs[__key.substr(0, indexof)]) == 'undefined') {
			                            indexs[__key.substr(0, indexof)] = [];
			                        }
			                        if (indexs[__key.substr(0, indexof)].indexOf(_index) < 0) {
			                            indexs[__key.substr(0, indexof)].push(_index);
			                        }
			                        __key = __key.replace('[', '_').replace(']', '_');
			 
			                    }
			 
			                    //console.log(__key);
			                    var keys = key.split('.');
			                    var path = '';
			                    var _path = '';
			                    var __path = '';
			                    for (var ik in keys) {
			                        var ikey = keys[ik];
			                        if (path == '') {
			                            path = keys[ik];
			                        } else {
			                            path = path + '.' + keys[ik];
			                        }
			                        var pathArr = path.match(/\[([^\]]+)\]/ig);
			                        if (__path == '') {
			                            __path = path;
			                        } else {
			                            __path = __path + '.' + ikey;
			                        }
			                        if (_path == '') {
			                            _path = path;
			                        } else {
			                            _path = _path + '.' + ikey;
			                        }
			                        //_path = path;
			                        for (var ip in pathArr) {
			                            var ipath = pathArr[ip];
			                            var indexof = __path.indexOf(ipath);
			                            var _index = __path.substr(0, indexof).replace('[', '_').replace(']', '_');
			                            if (indexof > -1) {
			                                _path = _path.replace(ipath, '[' + indexs[_index].indexOf(ipath) + ']');
			                                _path = _path.replace('[', '{').replace(']', '}');
			                            }
			                            if (_path.indexOf('[') < 0) {
			                                if (!isIndex) {
			                                    //初始化定义开始
			                                    var evelCode = 'resultParams.' + _path.replace(/\{/g, '[').replace(/\}/g, ']');
			                                    if (evelCode.substr(evelCode.length - 1, 1) == ']') {
			                                        if (typeof (eval(evelCode.substr(0, evelCode.lastIndexOf('[')))) == 'undefined') {
			                                            eval(evelCode.substr(0, evelCode.lastIndexOf('[')) + '=[];');
			                                        } else {
			                                            //console.log("hv", eval(evelCode.substr(0, evelCode.lastIndexOf('['))));
			                                        }
			                                    }
			                                    try {
			                                        if (typeof (eval(evelCode)) == 'undefined') {
			                                            eval(evelCode + '={};');
			                                        }
			                                    } catch (e) {
			                                        //console.log('error', evelCode);
			                                    }
			                                    //定义结束
			                                    //赋值
			                                    if (typeof (params[key]) != 'undefined') {
			                                        var keyArrays = key.split('.');
			                                        var codeArrays = evelCode.split('.');
			                                        if (keyArrays[keyArrays.length - 1] == codeArrays[codeArrays.length - 1]) {
			                                            try {
			                                                eval(evelCode + '=params[key];');
			                                            } catch (e) {
			                                                //console.log(path);
			                                            }
			                                        }
			                                    }
			                                }
			 
			                            }
			                        }
			                        __path = __path.replace('[', '_').replace(']', '_');
			                    }
			                } else {
			                    if (!isIndex) {
			                        var keys = key.split('.');
			                        var path = 'resultParams';
			                        for (var ik in keys) {
			                            path = path + '.' + keys[ik];
			                            try {
			                                if (typeof (eval(path)) == 'undefined') {
			                                    eval(path + '={};');
			                                }
			                            } catch (e) {
			                                //忽略不规则的
			                            }
			                        }
			                        try {
			                            eval(path + '=params[key];');
			                        } catch (e) {
			                            //忽略不规则的
			                        }
			                    }
			                }
			            }
			            return resultParams;
			        }
			        return null;
			    }
			};
		
		function ajaxSubmitForm(jsonString) {
			//console.log(jsonString);
			$.ajax({
		    	cache: false,
		    	type: "POST",
		        url:updateOneAction,
		        data:{rowstr:jsonString},// 你的formid
		        async: false,
		        error: function(request) {
		        	alert("保存有误");
		        },
		        success: function(data) {
		        	alert("保存成功");		            
		            if ("undefined" != typeof loactionurl) {
		            	window.location = loactionurl;
		            }
		        }
		    });
		}
		

		function ajaxSubmitFormOption(jsonString, updateAction, url) {
			//console.log(jsonString);
			$.ajax({
		    	cache: false,
		    	type: "POST",
		        url:updateAction,
		        data:{rowstr:jsonString},// 你的formid
		        async: false,
		        error: function(request) {
		        	alert("保存有误");
		        },
		        success: function(data) {
		            alert("保存成功");		
		           	
		            if ("undefined" != typeof url) {
		            	
		            	window.location = url;
		            }
		        }
		    });
		}
		
		function doSearch(){
			tableRef.datagrid('load',sy.serializeObject($("#searchform").form()));
		}
		
		function lookupRow(target){
			var rows = tableRef.datagrid('getRows');
			var rowIndex = getRowIndex(target);
			
			//console.log(rows[rowIndex]);
			doubleClick(rowIndex, rows[rowIndex]);
			
			//dialogRef.window('open');
			//LoadData(rows[rowIndex]);
			//formRef.form('load', rows[rowIndex]);
			
			var checkedItems = tableRef.datagrid('getChecked');
			var selected=false;
			$.each(checkedItems, function(index, item){
				//console.log(index+" "+item.scId+" " + rows[rowIndex].scId);
				if (rows[rowIndex].scId == item.scId) {
					selected = true;
				}
			});    
			
			if (selected) {
				tableRef.datagrid('unselectRow', rowIndex);  	
				
			}else {
				//console.log(selected);
				tableRef.datagrid('selectRow', rowIndex);  	
			}
		}
		
		function doubleClick(rowIndex, rowData){
			dialogRef.window('open');
			LoadData(rowData);
			formRef.form('load', rowData);
		}
		
		function addNewData(){
			dialogRef.window('open');
			//NewData();
			//LoadData(rowData);
			formRef.form('clear');
		}
		
		
		function endEditing(){
			if (editIndex == undefined){return true;}
			if (tableRef.datagrid('validateRow', editIndex)){
				//var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'id'});
				tableRef.datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			} else {
				return false;
			}
		}
		
		function updateActions(index){
			tableRef.datagrid('updateRow',{
				index:index,
				row:{}
			});
		}
		
		function getRowIndex(target){
			var tr = $(target).closest('tr.datagrid-row');
			return parseInt(tr.attr('datagrid-row-index'));
		}
		
		function editrow(target){
			tableRef.datagrid('beginEdit', getRowIndex(target));
		}
		
		
		function refresh() {
			tableRef.datagrid('reload');
		}
		
		function append(){
			tableRef.datagrid('appendRow', {});  
            var rows = tableRef.datagrid('getRows');  
            tableRef.datagrid('beginEdit', rows.length - 1);
		}
		
		
		function exportToExcelSelect(){
			$.messager.confirm('警告','将所选信息导出EXCEL吗？',function(r){
				if (r){
					var rows = tableRef.datagrid('getSelections');
					var rowstr = JSON.stringify(rows);
					window.location = './acSchoolfellowViewExportExcelSelect.action?rowstr='+rowstr;
				} 
			});
		}
		
		function pad(num, n) {  
		    var len = num.toString().length;  
		    while(len < n) {  
		        num = "0" + num;  
		        len++;  
		    }  
		    return num;  
		}
		
		 
		 $.extend({
			  getUrlVars: function(){
			    var vars = [], hash;
			    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
			    for(var i = 0; i < hashes.length; i++)
			    {
			      hash = hashes[i].split('=');
			      vars.push(hash[0]);
			      vars[hash[0]] = hash[1];
			    }
			    return vars;
			  },
			  getUrlVar: function(name){
			    return $.getUrlVars()[name];
			  }
			});
		
		 
		 function timeStamp2String(time){  
			    var datetime = new Date();  
			    datetime.setTime(time);  
			    var year = datetime.getFullYear();  
			    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;  
			    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();  
			    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();  
			    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();  
			    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();  
			    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;  
			}  
		 
		 
		 function sendwxtemplate(wxurl,data) {	
				$.ajax({
				    	type: "POST",	    
				        url:wxurl,
				        data:JSON.stringify(data),// 你的formid
//				        timeout : 100,
				        async: false,
				        error: function(request) {
				        	//alert("推送有误");
				        },
				        success: function(data) {
				        
				            //alert("推送成功");		            
				           
				        }
				    });
				 }